package cn.tedu.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Test2 {
    public static void main(String[] args) {
        ExecutorService pool= Executors.newFixedThreadPool(4);
        for (int i = 0; i < 4; i++) {
            MyTickets target=new MyTickets();
            pool.execute(target);
        }
    }
}
class MyTickets implements Runnable{
    int tickets=100;//问题：为什么不用静态修饰？
    @Override
    public void run() {
        while (true){
            synchronized ("hello"){
            if (tickets>0){
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"=="+tickets--);
            }else{
                break;
            }
            }
        }
    }
}
